(function(){"use strict";BX.namespace("BX.Landing");var e=BX.Landing.Utils.attr;var t=BX.Landing.Utils.data;var n=BX.Landing.Utils.encodeDataValue;var i=BX.Landing.Utils.decodeDataValue;BX.Landing.Block.Node.Img=function(e){BX.Landing.Block.Node.apply(this,arguments);this.type="img";this.editPanel=null;this.lastValue=null;this.field=null;this.uploadParams=e.uploadParams;if(!this.isGrouped()){this.node.addEventListener("click",this.onClick.bind(this))}if(this.isAllowInlineEdit()){this.node.setAttribute("title",BX.Landing.Loc.getMessage("LANDING_TITLE_OF_IMAGE_NODE"))}};function a(e){return e.node.nodeName!=="IMG"}function s(e){return e.node.nodeName==="IMG"}function d(e){return e.node.nodeName==="SPAN"||e.node.nodeName==="I"||e.node.nodeName==="EM"}function o(e){var t=e.node.style.getPropertyValue("background-image");if(t){var n=t.match(/url\((.*?)\)/);if(n&&n[1]){return n[1].replace(/["|']/g,"")}}return""}function r(e){var t=e.node.style.getPropertyValue("background-image");if(t){var n=t.match(/1x, url\(["|'](.*)["|']\) 2x\)/);if(n&&n[1]){return n[1].replace(/["|']/g,"")}}return""}function l(e){var t=parseInt(e.node.dataset.fileid);return t===t?t:-1}function c(e){var t=parseInt(e.node.dataset.fileid2x);return t===t?t:-1}function u(t){var n=e(t.node,"alt");return!!n?n:""}function g(e){var n=t(e.node,"data-pseudo-url");return!!n?n:""}function h(t){var n=e(t.node,"src");return!!n?n:""}function f(t){var n=e(t.node,"srcset");return!!n?n.replace(" 2x",""):""}function m(e,t){if(!s(e)){var n=BX.create("img",{attrs:{src:t.src,alt:t.alt,"data-fileid":t.id}});e.node.parentNode.insertBefore(n,e.node);BX.remove(e.node);e.node=n}else{e.node.src=t.src;e.node.alt=t.alt||"";e.node.dataset.fileid=t.id||-1;e.node.srcset=t.src2x?t.src2x+" 2x":"";e.node.dataset.fileid2x=t.id2x||-1}}function p(e,t){if(!a(e)){var n=BX.create("div",{attrs:{style:'background-image: url("'+t.src+'")',"data-fileid":t.id}});e.node.parentNode.insertBefore(n,e.node);BX.remove(e.node);e.node=n}else{if(t.src){const n=['background-image: url("'+t.src+'");'];if(t.src2x){n.push('background-image: -webkit-image-set(url("'+t.src+'") 1x, url("'+t.src2x+'") 2x);');n.push('background-image: image-set(url("'+t.src+'") 1x, url("'+t.src2x+'") 2x);')}const i=e.node.style;const a={};Array.from(i).map((e=>{a[e]=i.getPropertyValue(e)}));e.node.setAttribute("style",n.join(" "));for(let t in a){if(t!=="background-image"){e.node.style.setProperty(t,a[t])}}}else{if(e.node.style){e.node.style.removeProperty("background-image")}}e.node.dataset.fileid=t.id||-1;e.node.dataset.fileid2x=t.id2x||-1}}BX.Landing.Block.Node.Img.prototype={__proto__:BX.Landing.Block.Node.prototype,constructor:BX.Landing.Block.Node.Img,onClick:function(e){if(this.manifest.allowInlineEdit!==false&&BX.Landing.Main.getInstance().isControlsEnabled()&&(!BX.Landing.Block.Node.Text.currentNode||!BX.Landing.Block.Node.Text.currentNode.isEditable())&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){e.preventDefault();e.stopPropagation();BX.Landing.UI.Button.ColorAction.hideAll();if(!this.editPanel){this.editPanel=new BX.Landing.UI.Panel.Content(this.selector,{title:BX.Landing.Loc.getMessage("LANDING_IMAGE_PANEL_TITLE"),className:"landing-ui-panel-edit-image"});this.editPanel.appendFooterButton(new BX.Landing.UI.Button.BaseButton("save_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_SAVE"),onClick:this.save.bind(this),className:"landing-ui-button-content-save"}));this.editPanel.appendFooterButton(new BX.Landing.UI.Button.BaseButton("cancel_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_CANCEL"),onClick:this.editPanel.hide.bind(this.editPanel),className:"landing-ui-button-content-cancel"}));window.parent.document.body.appendChild(this.editPanel.layout)}var t=new BX.Landing.UI.Form.BaseForm({title:this.manifest.name});t.addField(this.getField());this.editPanel.clear();this.editPanel.appendForm(t);this.editPanel.show();BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}},save:function(){var e=this.editPanel.forms[0].fields[0].getValue();if(JSON.stringify(this.getValue())!==JSON.stringify(e)){this.setValue(e)}this.editPanel.hide()},getField:function(){if(!this.field){var e="";if(this.manifest.dimensions){var t=this.manifest.dimensions;var n=t.width||t.maxWidth||t.minWidth;var s=t.height||t.maxHeight||t.minHeight;if(n&&!s){e=BX.Landing.Loc.getMessage("LANDING_CONTENT_IMAGE_RECOMMENDED_WIDTH")+" ";e+=n+"px"}else if(s&&!n){e=BX.Landing.Loc.getMessage("LANDING_CONTENT_IMAGE_RECOMMENDED_HEIGHT")+" ";e+=s+"px"}else if(n&&s){e=BX.Landing.Loc.getMessage("LANDING_CONTENT_IMAGE_RECOMMENDED_SIZE")+" ";e+=n+"px&nbsp;/&nbsp;";e+=s+"px"}}var d=this.getValue();d.url=i(d.url);var o=!!this.node.closest("a")||!!this.manifest.disableLink;if(this.manifest["editInStyle"]!==true){this.field=new BX.Landing.UI.Field.Image({selector:this.selector,title:this.manifest.name,description:e,disableLink:o,content:d,dimensions:!!this.manifest.dimensions?this.manifest.dimensions:{},create2xByDefault:this.manifest.create2xByDefault,disableAltField:a(this),uploadParams:this.uploadParams})}}else{this.field.setValue(this.getValue());this.field.content=this.getValue();requestAnimationFrame(function(){this.field.adjustPreviewBackgroundSize()}.bind(this))}return this.field},setValue:function(t,n,i){this.lastValue=this.lastValue||this.getValue();this.preventSave(n);t.src=decodeURIComponent(t.src);if(s(this)){m(this,t)}if(a(this)){p(this,t)}if(t.url){const n=this.preparePseudoUrl(t.url);if(n!==null){e(this.node,"data-pseudo-url",n)}}this.onChange(i);if(!i){BX.Landing.History.getInstance().push()}this.lastValue=this.getValue()},getValue:function(){const e={type:"",src:"",alt:"",url:""};const t=l(this);if(t>0){e.id=t}const i=c(this);if(i>0){e.id2x=i}if(a(this)){e.type="background";e.src=o(this);const t=r(this);if(t){e.src2x=t}}if(s(this)){e.type="image";e.alt=u(this);e.src=h(this);const t=f(this);if(t){e.src2x=t}}e.url=n(g(this))||{text:"",href:"",target:"_self",enabled:false};return e}}})();
//# sourceMappingURL=img.map.js